

import 'package:flutter/material.dart';
import 'package:xim/common/style/colors.dart';
import 'package:xim/http/apis/user/user_model.dart';
import 'package:xim/widget/common/state.dart';
import 'package:xim/common/get_style_view.dart';
import 'package:xim/widget/common/ui/cell.dart';


class ProfilePublicStyle extends Style with AppBarMixin {

  @override
  Color get appBarBgColor => defaultCellBgColor.color;

  @override
  String get appBarTitle => "";

  @override
  List<ModelColor> get modelColors => [
    ...super.modelColors,
    userNameColor,
    accountColor,
    fgColor,
    bgColor,
    defaultOptionBtnBgColor,
    defaultCellBgColor,
  ];
  @override
  ModelColor bgColor = ModelColor(lightColor: const Color(0xffededed), darkColor: const Color(0xff111111));
  ModelColor userNameColor = ModelColor(lightColor: const Color(0xff191919), darkColor: const Color(0xffd1d1d1));
  ModelColor accountColor = ModelColor(lightColor: const Color(0xff737373), darkColor: const Color(0xff8c8c8c));
  ModelColor fgColor = ModelColor(lightColor: const Color(0xfffefefe), darkColor: const Color(0xff181818));
  ModelColor deleteFriendTextColor = ModelColor(lightColor: const Color(0xfffe473d), darkColor: const Color(0xfffe473d));
  ModelColor defaultOptionBtnBgColor = ModelColor(lightColor: Colors.white, darkColor: const Color(0xff191919));
  ModelColor defaultCellBgColor = ModelColor(lightColor: const Color(0xfffefefe), darkColor: const Color(0xff181818));

  var horizontalPadding =  const EdgeInsets.symmetric(horizontal: 16);

  Widget userHeader(UserInfoModel userInfo){
    return Row(
      children: [
        ClipRRect(
            borderRadius: const BorderRadius.all(Radius.circular(8)),
            child: Image.network(userInfo.avatar??'', width: 70,)
        ),
        const SizedBox(width: 12,),
        Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(userInfo.name??'', style: TextStyle(fontSize: 18, color: userNameColor.color),),
            const SizedBox(height: 8,),
            Text("账号：${userInfo.account??''}", style: TextStyle(fontSize: 14, color: accountColor.color),),
            Text("IP：${'成都'}", style: TextStyle(fontSize: 14, color: accountColor.color),),
          ],
        )
      ],
    );
  }


  Widget settingNodeCompose() => Cell.titleCell(
    title: "设置备注", titleStyle: TextStyle(color: userNameColor.color),
    decoration: BoxDecoration(color: defaultCellBgColor.color,),
    padding: EdgeInsets.symmetric(horizontal: horizontalPadding.left, vertical: 12),
    rightItem: Cell.iconItem(
        iconData: Icons.chevron_right,
        iconStyle: IconStyle(size: 14, color: userNameColor.color)
    ),
  );

  Widget friendSource(String source) => Cell(
    leftItem: Row(
      children: [
        Text("来源", style: TextStyle(color: userNameColor.color),),
        const SizedBox(width: 18,),
        Text(source, style: TextStyle(fontSize: 14, color: weakTextColor.color),)
      ],
    ),
    decoration: BoxDecoration(color: defaultCellBgColor.color,),
    padding: EdgeInsets.symmetric(horizontal: horizontalPadding.left, vertical: 12),
    rightItem: const SizedBox(),
  );

  Widget attachMessage(String attachMessage) => Cell(
    leftItem: Row(
      children: [
        Text("备注信息", style: TextStyle(color: userNameColor.color),),
        const SizedBox(width: 18,),
        Text(attachMessage, style: TextStyle(fontSize: 14, color: weakTextColor.color),)
      ],
    ),
    decoration: BoxDecoration(color: defaultCellBgColor.color,),
    padding: EdgeInsets.symmetric(horizontal: horizontalPadding.left, vertical: 12),
    rightItem: const SizedBox(),
  );

  Widget moreInfoCompose({Function()? onTab}) => Cell.titleCell(
    title: "更多信息", titleStyle: TextStyle(color: userNameColor.color),
    decoration: BoxDecoration(color: defaultCellBgColor.color,),
    padding: EdgeInsets.symmetric(horizontal: horizontalPadding.left, vertical: 12),
    rightItem: Cell.iconItem(iconData: Icons.chevron_right, iconStyle: IconStyle(size: 14, color: userNameColor.color)),
    onTab: ()=>onTab?.call(),
  );

  Widget advancedCompose({Function()? onTab}) => Cell.titleCell(
    title: "高级",
    titleStyle: TextStyle(color: userNameColor.color),
    decoration: BoxDecoration(color: defaultCellBgColor.color,),
    padding: EdgeInsets.symmetric(horizontal: horizontalPadding.left, vertical: 12),
    rightItem: Cell.iconItem(iconData: Icons.chevron_right, iconStyle: IconStyle(size: 14, color: userNameColor.color)),
  );


  Widget optionBtn(String title, {Function()? onTap, ModelColor? bgColor, ModelColor? titleColor}){
    return GestureDetector(
      behavior:HitTestBehavior.opaque,
      onTap: ()=>onTap?.call(),
      child: Container(
          color: bgColor?.color ?? defaultOptionBtnBgColor.color,
          padding: const EdgeInsets.symmetric(vertical: 14),
          child: Center(
            child: Text(
              title,
              style: TextStyle(
                fontSize: 16,
                color: titleColor?.color ?? userNameColor.color
              )
            ),
          )
      ),
    );
  }
}